package com.frkj.yuan.api.presenter;
import com.frkj.yuan.api.bean.JiuzhenPersonalListBean;
import com.frkj.yuan.api.bean.BaseStringMsgBean;
import com.frkj.yuan.api.category.JiuzhenPersonListCatefory;
import com.frkj.yuan.utils.RetrofitUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
 * 信息说明:
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/22 16 ：59
 * 项目名称：yuanban
 */
public class JiuzhenPersonListPresenter implements JiuzhenPersonListCatefory.Presenter {
    JiuzhenPersonListCatefory.View view;
    public JiuzhenPersonListPresenter(JiuzhenPersonListCatefory.View view) {
        this.view = view;
    }
    @Override
    public void getAddjiuzhenPerson(String token,int pageNum ,int pageSize,String requestBody) {
        RequestBody  body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestBody);
        RetrofitUtil.getInstance().getmService().getPerson(token,pageNum,pageSize,body).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    JiuzhenPersonalListBean userInfor = gson.fromJson(result, JiuzhenPersonalListBean.class);
                    view.getAddjiuzhenPerson(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
    @Override
    public void getDelete(String token, long patientId, long UserId) {
        RetrofitUtil.getInstance().getmService().getDelete(token,patientId,UserId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    BaseStringMsgBean userInfor = gson.fromJson(result, BaseStringMsgBean.class);
                    view.DeleteMsg(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
}
